package ace.cmp.jetcache.anno.config;

import java.util.ArrayList;
import java.util.List;
import org.springframework.context.annotation.AdviceMode;
import org.springframework.context.annotation.AdviceModeImportSelector;
import org.springframework.context.annotation.AutoProxyRegistrar;

/**
 * @author caspar
 * @date 2023/8/8 10:28
 * 扩展 {@link com.alicp.jetcache.anno.config.ConfigSelector} 支持扫描类
 */
public class AceConfigSelector extends AdviceModeImportSelector<EnableAceMethodCache> {

  @Override
  public String[] selectImports(AdviceMode adviceMode) {
    switch (adviceMode) {
      case PROXY:
        return getProxyImports();
      case ASPECTJ:
        //                return getAspectJImports();
      default:
        return null;
    }
  }

  /**
   * Return the imports to use if the {@link AdviceMode} is set to {@link AdviceMode#PROXY}.
   * <p>Take care of adding the necessary JSR-107 import if it is available.
   */
  private String[] getProxyImports() {
    List<String> result = new ArrayList<String>();
    result.add(AutoProxyRegistrar.class.getName());
    result.add(AceJetCacheProxyConfiguration.class.getName());
    return result.toArray(new String[result.size()]);
  }

  /**
   * Return the imports to use if the {@link AdviceMode} is set to {@link AdviceMode#ASPECTJ}.
   * <p>Take care of adding the necessary JSR-107 import if it is available.
   */
  //    private String[] getAspectJImports() {
  //        List<String> result = new ArrayList<String>();
  //        result.add(CACHE_ASPECT_CONFIGURATION_CLASS_NAME);
  //        return result.toArray(new String[result.size()]);
  //    }
}
